package com.jxs.android.weixi;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.telecom.weixi.R;

public class LaucherAppAdpter extends BaseAdapter {

	/**
	 * @Des 这里是图片和文字的集合
	 * @return
	 */
	private List<AppInfo> getAppInfos() {

		List<AppInfo> appInfos = new ArrayList<AppInfo>();
		appInfos.add(new AppInfo(R.string.search_user, R.color.white, R.drawable.icon_home_user_search));
		appInfos.add(new AppInfo(R.string.search_term, R.color.white, R.drawable.icon_home_term_search));
		appInfos.add(new AppInfo(R.string.search_owe, R.color.white, R.drawable.icon_home_owe_search));

		appInfos.add(new AppInfo(R.string.home_cust, R.color.gray, R.drawable.ic_mycustomer));
		appInfos.add(new AppInfo(R.string.home_work, R.color.gray, R.drawable.ic_mywork));
		appInfos.add(new AppInfo(R.string.home_succ, R.color.gray, R.drawable.ic_performance));
		appInfos.add(new AppInfo(R.string.home_help, R.color.gray, R.drawable.ic_syshelp));

		return appInfos;
	}

	private class AppInfo {
		int imgResid;
		int textResid;
		int colorResid;

		public AppInfo(int textResid, int colorResid, int imgResid) {
			this.imgResid = imgResid;
			this.textResid = textResid;
			this.colorResid = colorResid;
		}

	}

	private List<AppInfo> appInfos = getAppInfos();

	private LayoutInflater inflater = null;
	private ViewHolder holder = null;
	private Context context;

	public LaucherAppAdpter(Context context) {
		this.context = context;
		inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		return appInfos.size();
	}

	@Override
	public AppInfo getItem(int position) {
		return appInfos.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		if (convertView == null) {
			convertView = inflater.inflate(R.layout.bu_img_tv_item, null);
			holder = new ViewHolder();
			holder.icon_iv = (ImageView) convertView.findViewById(R.id.gridView_ImageViewItem);
			holder.name_tv = (TextView) convertView.findViewById(R.id.gridView_TextViweItem);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		AppInfo appInfo = appInfos.get(position);

		if (appInfo.colorResid == -1) {
			holder.name_tv.setTextColor(context.getResources().getColor(R.color.menu_item_color));
		} else {
			holder.name_tv.setTextColor(context.getResources().getColor(appInfo.colorResid));
		}
		holder.icon_iv.setImageResource(appInfo.imgResid);
		holder.name_tv.setText(appInfo.textResid);
		return convertView;
	}

	private class ViewHolder {
		ImageView icon_iv;
		TextView name_tv;
	}

}